#ifndef SHELF_H
#define SHELF_H

#include <QObject>
#include <QMutex>
#include <QVector>

struct Book{

    QMutex *mutex;
    QString writerName;

    Book(QString writerName) : writerName(writerName){
        mutex = new QMutex();
    }

    bool tryLock(){
        return mutex->tryLock();
    }

    void unlock(){
        mutex->unlock();
    }
};

class Shelf : public QObject
{
    Q_OBJECT
public:
    explicit Shelf(int maxBookCount, QObject *parent = 0);
    bool tryTakeBookForRead(int &index);
    bool tryTakeBookForEdit(QString writerName, int &index);
    void tryPutBook(int index);
    bool tryPutNewBook(QString writerName);

signals:
    
public slots:

private:
    int maxBookCount;

    QVector<Book*> books;
};

#endif // SHELF_H
